﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using AspNetCs.Model;
using AspNetCs.IDAL;
using AspNetCs.SQLServerDAL;
using AspNetCs.DALFactory;
using AspNetCs.Common;

namespace AspNetCs.Bll
{
    public class VideoBLL
    {
        private IVideo videoDAL = Conn.CreateVideo();

        public int Add(VideoModel model)
        {
            return videoDAL.Add(model);
        }

        public int Update(VideoModel model)
        {
            return videoDAL.Update(model);
        }

        public DataTable GetDataTable(string filter)
        {
            return videoDAL.GetDataTable(filter);
        }

        private VideoModel GetModel(DataRow row)
        {
            VideoModel model = new VideoModel();
            model.Id =StringHelper.isNumber_int(row["id"].ToString());
            model.Address1 = row["Address1"].ToString();
            model.Address2 = row["Address2"].ToString();
            model.Address3 = row["Address3"].ToString();
            model.Address4 = row["Address4"].ToString();
            model.Address5 = row["Address5"].ToString();
            model.Description = row["Description"].ToString();
            model.Id =StringHelper.isNumber_int(row["Id"].ToString());
            model.Pic = row["Pic"].ToString();
            model.Title = row["Title"].ToString();
            model.VideoType = row["VideoType"].ToString();
            return model;
        }

        public VideoModel GetModel(string filter)
        {
            VideoModel model = new VideoModel();
            DataTable dataTable = new DataTable();
            dataTable = GetDataTable(filter);
            if(dataTable.Rows.Count>0)
            {
                model=GetModel(dataTable.Rows[0]);
            }
            return model;
        }
    }
}
